home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Arsenal Files 4
/
The Arsenal Files 4 (Arsenal Computer).ISO
/
casm
/
au116-as.exe
/
UTIL
/
CFG_HAND.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-22
|
2KB
|
89 lines
#include "..\au.hpp"
#include <errno.h>
/**************************************************************************/
/* open the configuration file, look through path if necessary */
STATUS CFG_HANDLE::open(AU *au, char *fn)
{
int pathpos=0, dirpos;
char *path, aupath[200], directory[80];
char temp[FILE_SIZE];
strcpy(file_name, fn);
line_number = 0;
if (handle.open(au, file_name, O_TEXT) == SUCCESS)
return SUCCESS;
if (strstr(file_name, "\\") != NULL)
return FAILURE;
/* Lets try ripping it from argv[0] */
split_file(au->argv0, directory, temp);
build_fname(directory, directory, file_name);
if (handle.open(au, directory, O_TEXT) == SUCCESS)
return SUCCESS;
/* lets try for AUPATH envirnonment variable */
if (getenv("AUPATH")!=NULL)
{
strcpy(aupath, getenv("AUPATH"));
append_backslash(aupath);
strcat(aupath, file_name);
if (handle.open(au, aupath, O_TEXT) == SUCCESS)
return SUCCESS;
}
/* Lets try the path */
path = getenv("PATH");
if (path == NULL)
return FAILURE;
while (TRUE)
{
if (path[pathpos]=='\0') /* we have looked through the whole PATH without success */
return FAILURE;
dirpos=0;
while (path[pathpos]!=';' && path[pathpos]!='\0')
directory[dirpos++] = path[pathpos++];
if (path[pathpos] == ';')
pathpos++; /* get us over the ; */
directory[dirpos] = '\0';
append_backslash(directory);
strcat(directory, file_name);
if (handle.open(au, directory, O_TEXT) == SUCCESS)
return SUCCESS;
}
}
int CFG_HANDLE::read_line(AU *au, char *string)
{
int retCode;
retCode = handle.read_line(au, string);
if (retCode == 0)
line_number++;
return retCode;
}
/*****************************************************************************/
void CFG_HANDLE::invalid_option(AU *au, char *option)
{
au_printf_error(au, "Unknown command \"%s\" in %s at line %d",
option, file_name, line_number);
exit(0);
}
/*****************************************************************************/
void CFG_HANDLE::invalid(AU *au, char *msg)
{
au_printf_error(au, "%s in %s at line %d", msg, file_name, line_number);
exit(0);
}